using System;
using System.Windows;
using System.Data;
using System.Xml;
using System.Configuration;
using System.Collections;
using System.Text.RegularExpressions;
using SqlMiM.Properties;
using System.Runtime.InteropServices;
using System.Text;
using System.ComponentModel;
using System.IO;
using SqlMiM.Common.Themes;
using SqlMiM.Common.Framework.Configuration;
using SqlMiM.Common.Sql;
using SqlMiM.Common;
using System.Data.SqlClient;
using SqlMiM.Common.Messages;
using System.Windows.Input;
using SqlMiM.Common.ViewModel;
using SqlMiM.Common.Model;


namespace SqlMiM
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>

    public partial class App : Application
    {
        MainWindow mainWindow;

        public App()
        {
            InitializeComponent();

            // Initialize Context
            Context.Current.Initialize();


        }


        void ApplicationStartup(object sender, StartupEventArgs e)
        {

            // Launch authentication
            LoginWindow login = new LoginWindow();

            SqlConnectionStringBuilder sqlConnectionStringBuilder = null;
            Server server = null;

            bool? isComplete = login.ShowDialog(out sqlConnectionStringBuilder, out server);

            if ((!isComplete.HasValue) || (isComplete.HasValue && !isComplete.Value))
            {
                Application.Current.Shutdown();
            }
            else
            {
                // Set Current Server and SqlConnectionStringBuilder;
                Context.Current.SetConnectionAndServer(sqlConnectionStringBuilder, server);

                // Create mainwindow
                mainWindow = new MainWindow();

                // Set new mainwindow
                Application.Current.MainWindow = mainWindow;

                // Launch new MainWindows
                mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;

                mainWindow.Show();

            }
        }


    }
}